home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-hpux11.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-15  |  2.8 KB  |  108 lines

  1. /* ieee-utils/fp-hpux11.c
  2.  * 
  3.  * Copyright (C) 2001 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define _INCLUDE_HPUX_SOURCE
  21.  
  22. #include <math.h>
  23. #include <stdio.h>
  24. #include <fenv.h>
  25. #include <gsl/gsl_ieee_utils.h>
  26. #include <gsl/gsl_errno.h>
  27.  
  28. int
  29. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  30. {
  31.   int mode;
  32.  
  33.   switch (precision)
  34.     {
  35.     case GSL_IEEE_SINGLE_PRECISION:
  36.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  37.          GSL_EUNSUP) ;
  38.       break ;
  39.     case GSL_IEEE_DOUBLE_PRECISION:
  40.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  41.          GSL_EUNSUP) ;
  42.       break ;
  43.     case GSL_IEEE_EXTENDED_PRECISION:
  44.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  45.          GSL_EUNSUP) ;
  46.       break ;
  47.     }
  48.  
  49.  
  50.   switch (rounding)
  51.     {
  52.     case GSL_IEEE_ROUND_TO_NEAREST:
  53.       fesetround (FE_TONEAREST) ;
  54.       break ;
  55.     case GSL_IEEE_ROUND_DOWN:
  56.       fesetround (FE_DOWNWARD) ;
  57.       break ;
  58.     case GSL_IEEE_ROUND_UP:
  59.       fesetround (FE_UPWARD) ;
  60.       break ;
  61.     case GSL_IEEE_ROUND_TO_ZERO:
  62.       fesetround (FE_TOWARDZERO) ;
  63.       break ;
  64.     default:
  65.       fesetround (FE_TONEAREST) ;
  66.     }
  67.  
  68.   /* Turn on all the exceptions apart from 'inexact' */
  69.  
  70.   mode = FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW ;
  71.  
  72.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  73.     mode &= ~ FE_INVALID ;
  74.  
  75.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  76.     {
  77.       /* do nothing */
  78.     }
  79.   else
  80.     {
  81.       GSL_ERROR ("HP-UX does not support the denormalized operand exception. "
  82.          "Use 'mask-denormalized' to work around this.",
  83.          GSL_EUNSUP) ;
  84.     }
  85.  
  86.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  87.     mode &= ~ FE_DIVBYZERO ;
  88.  
  89.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  90.     mode &= ~ FE_OVERFLOW ;
  91.  
  92.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  93.     mode &=  ~ FE_UNDERFLOW ;
  94.  
  95.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  96.     {
  97.       mode |= FE_INEXACT ;
  98.     }
  99.   else
  100.     {
  101.       mode &= ~ FE_INEXACT ;
  102.     }
  103.  
  104.   fesettrapenable (mode) ;
  105.  
  106.   return GSL_SUCCESS ;
  107. }
  108.